<?php

require_once dirname(__FILE__) . '/../lib/bb_penalizacionGeneratorConfiguration.class.php';
require_once dirname(__FILE__) . '/../lib/bb_penalizacionGeneratorHelper.class.php';

/**
 * bb_penalizacion actions.
 *
 * @package    ingenyo-biblio
 * @subpackage bb_penalizacion
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class bb_penalizacionActions extends autoBb_penalizacionActions
{

  public function executeNew(sfWebRequest $request)
  {
    parent::executeNew($request);
    $this->setLayout('layout_iframe'); 
    
  }

  public function executeIndexByPersona(sfWebRequest $request)
  {
    parent::executeIndex($request);
    $c = BbPenalizacionQuery::getQueryByIdPersona($this->getUser()->getAttribute('id_persona'));
    $this->pager->setQuery($c);
    $this->pager->init();
    $this->setTemplate('index');
    $this->setLayout('layout_iframe');

  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->form = $this->configuration->getForm();
    $this->BbPenalizacion = $this->form->getObject();

    if ($this->processForm($request, $this->form))
    {
      $this->setTemplate('confirm');
    }
    else
    {
      $this->setTemplate('new');
    }

  }
  
    public function executeUpdate(sfWebRequest $request)
  {
    $this->BbPenalizacion = $this->getRoute()->getObject();
    $this->form = $this->configuration->getForm($this->BbPenalizacion);

    if ($this->processForm($request, $this->form))
    {
      $this->redirect('bb_penalizacion/indexByPersona');
    }
    else
    {
      $this->setTemplate('edit');
    }
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';

      $BbPenalizacion = $form->save();

      $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $BbPenalizacion)));

      if ($request->hasParameter('_save_and_add'))
      {
        $this->getUser()->setFlash('notice', $notice . ' You can add another one below.');

        $this->redirect('@bb_penalizacion_new');
      }
      else
      {
        $this->getUser()->setFlash('notice', $notice);

        return true;
      }
    }
    else
    {
      $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
      return false;
    }

  }

}
